<template>
    <div class="username_container">
        <HeaderTop :goBack="true" :headTitle="'修改用户名'"></HeaderTop>
        <section class="username">
            <div class="username_div">
                <input type="text" placeholder="请输入用户名" :class="{'alert':!earn}" v-model="text">
                <p v-if="earn">用户名只能修改一次（5-10字符之间）</p>
                <p class="unlikep" v-else>用户名长度在5到10位之间</p>
                <div class="submit_btn" @click="resetName">确认修改</div>
            </div>
        </section>
    </div>
</template>

<script>
import HeaderTop from '@src/components/header/HeaderTop';
import {changeUserInfo, mapActions} from 'vuex'

export default {
    components:{
        HeaderTop
    },
    data(){
        return {
            text:'',
            earn:true
        }
    },
    methods:{
        ...mapActions(['changeUserInfo']),
        resetName(){
            if(this.text.length<5 || this.text.length>10){
                this.earn=false;
                setTimeout(()=>{
                    this.earn=true;
                },2000)
                return;
            }
            this.changeUserInfo(this.text);
            this.$router.go(-1);
        }
    }
}
</script>

<style lang="scss" scoped>
@import '~@styl/mixin.scss';
.username_container{
    position: absolute;
    top:0;
    left: 0;
    right: 0;
    bottom: 0;
    background: $bc;
    .username{
        padding: 1.95rem 0.2rem 0;
        background: $blue;
        .username_div{
            background: #fff;
            padding: 0.2rem 0 0;
            display: flex;
            flex-direction: column;
            input{
                margin-left: 0.5rem;
                margin-right: 0.5rem;
                box-sizing: border-box;
                display: block;
                height: 1.5rem;
                @include sc(0.65rem,#333);
                border-bottom: 0.025rem solid $bc;
                &.alert{
                    border: 0.025rem solid #f00;
                }
            }
            p{
                @include sc(0.45rem,#999);
                padding: 0.3rem 0.5rem;
                line-height: 0.6rem;
            }
            .unlikep{
                color: #f00;
            }
            .submit_btn{
                background: $blue;
                line-height: 2rem;
                @include sc(0.65rem,#fff);
                text-align: center;
            }
        }
    }
}
</style>